package com.googlecode.bipol.war.services;

import com.googlecode.bip.dao.TopicDAO;
import com.googlecode.bip.entity.ITopic;
import com.googlecode.bip.entity.Topic;

public class TopicManagerImpl implements TopicManager {

	@Override
	//FIXME: Currently, the topic is always created
	public ITopic createTopic(String name, String description, String idLocal) throws ServiceException {		
		// Create the topic based on properties 
		Topic t = new Topic();
		t.setName(name);
		t.setDescription(description);
		t.setIdLocal(idLocal);
		// Insert the new topic
		try {
			if (new TopicDAO().insertTopic(t)) {
				return t;
			} else {
				throw new ServiceException("Error when saving topic: Unknown reason (please contact the administrator)");
			}
		} catch(Exception e) {
			throw new ServiceException("Error when saving topic: "+e.getMessage());
		}
	}

}
